<?php
// +-------------------------------------------------------------------
// |
// +-------------------------------------------------------------------
// | Copyright (c) 2009-2016 All rights reserved.
// +-------------------------------------------------------------------
namespace Service\Api\V1;

use Think\Exception;
use Think\Model;

class HouseRefund
{
    public $login = false; //是否需要登录才能访问该接口
    public $title = "012退租申请ok";
    public $group = '用户';
    public $desc = "";

    public $input = [
        'id' => 'required;int;label=合同id',
        'refund_real_name' => 'required;label=退款账号真实姓名',
        'refund_card_no' => 'required;label=退款账号',
        'refund_bank' => 'required;label=开户行',
        'refund_date' => 'required;label=申请退租时间;comment=格式：2020-03-05',
    ];

    public $output = [
    ];

    public function run($param, $uid, $login_info)
    {
        $contact = M('house_contract')->where(['id' => $param['id']])->find();
        $housse_refund = M('refund_house')->where([
            'contact_code' => $contact['code'],
            'uid' => $uid,
            'state' => ['in', '1,3'],
        ])->find();
        if(isset($housse_refund['id'])) throw new Exception('已提交退租申请');
        $add = [
            'uid' => $uid,
            'contact_code' => $contact['code'],
            'building_id' => $contact['building_id'],
            'house_id' => $contact['house_id'],
            'chengzufang' => $contact['chengzufang'],
            'signed_time' => $contact['sign_time'],
            'start_time' => $contact['start_time'],
            'end_time' => $contact['end_time'],
            'refund_real_name' => $param['refund_real_name'],
            'refund_card_no' => $param['refund_card_no'],
            'refund_bank' => $param['refund_bank'],
            'refund_date' => $param['refund_date'],
        ];
        $flag = M('refund_house')->add($add);
        if($flag === false){
            throw new Exception('退租失败');
        }
        return [
        ];
    }
}
